from tortoise import fields
from tortoise.models import Model
from enum import IntEnum

class WarehouseStatus(IntEnum):
    DISABLED = 0
    ENABLED = 1

class Warehouse(Model):
    """仓库信息模型"""
    
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255, description='仓库名称')
    address = fields.CharField(max_length=255, description='仓库地址')
    status = fields.IntField(default=1, description='仓库状态：1-正常，0-停用')
    create_at = fields.DatetimeField(auto_now_add=True, description='创建时间')
    update_at = fields.DatetimeField(auto_now=True, description='更新时间')

    # 反向关系
    goods_relations: fields.ReverseRelation["WarehouseGoods"]

    class Meta:
        table = "warehouse"
        table_description = "仓库信息表"
        unique_together = (("name", "address"),)

    def __str__(self):
        return f"{self.name} ({self.address})"

    @property
    def is_active(self) -> bool:
        """检查仓库是否处于启用状态"""
        return self.status == WarehouseStatus.ENABLED
 